const app = getApp();
Page({
  data: {
    navIndex: 0,
    nav: [
      {
        title: '全部订单',
        value: 'all',
      }, {
        title: '待支付',
        value: 'unpay',
      }, {
        title: '待发货',
        value: 'unsend',
      }, {
        title: '待收货',
        value: 'unreceive',
      }, {
        title: '已完成',
        value: 'finished',
      }, {
        title: '退货/退款',
        value: 'service',
      },
    ],
    order: [],
    page: 0,
    specType: 1,
  },
  onLoad: function (options) {
    let that = this;
    that.setData({
      navIndex: options.index,
    })
  },
  onShow: function () {
    let that = this;
    that.setData({
      page: 0,
      order: [],
    },()=>{
      that.getInfo();
    })
  },
  getInfo(){
    let that = this;
    let page = that.data.page + 1;
    let type = that.data.nav[that.data.navIndex].value;
    wx.showLoading({
      title: '加载中...',
    })
    app.request('order/index', { type, page },'GET',false,function(res){
      let order = that.data.order;
      order.push(...res.data.data.data);
      that.setData({
        order: order,
        page: page,
        pageShow: true,
      })
    })
  },
  navChoose: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.index;
    that.setData({
      navIndex: index,
      page: 0,
      order: [],
    },()=>{
      that.getInfo();
    })
  },
  skipPage: function (e) {
    app.skipPage(e);
  },
  onPullDownRefresh: function () {

  },
  onReachBottom: function () {
    this.getInfo();
  },
  onShareAppMessage: function () {
    return{
      path: '/pages/index/index'
    }
  }
})